<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Orderlist_m extends CI_Model {
	function __construct()
    {
        parent::__construct();
    }
	
	/*****************
	** 查询订单搜索脚本
	** $id int
	*************/
	function getordersearch($id ='')
	{
		$this->db->order_by("name","ASC");
		$post=array("status"=>0);
		if($id)$post=array("id"=>$id);
		return $this->db->get_where("db_order_search",$post)->result_array();
	}

	/*****************
	** 查询订单商品
	** $id int
	*************/
	function getOrderlistSell($id)
	{
		
		if(!$id)die("参数错误！");
		if($id)$post=array("order_id"=>$id);
		$res = $this->db->get_where("db_order_sell",$post)->result_array();
		$allcosprice = 0;
		
		foreach($res as $key=>$goods)
		{
			$goods_id = $goods["goods_id"];
			
				$rsdb = $this->fun->getdatabasesdetail("db_goods"," AND goods_id='".$goods_id."'");
				if($rsdb)
				{
					
					$stock = $this->fun->getstock($goods_id);
					if($stock)
					{
						$res[$key]["stock"] = $stock;
					}else{
					
						$res[$key]["stock"] = array("id"=>0);	
					}

					$goods_name = $rsdb["goods_name"];
				}

			if($goods["costprice"])
			{
				$g_costprice = $goods["costprice"];
			}else{
				$g_costprice= $rsdb["g_costprice"];
			}
			$res[$key]["g_costprice"] = $g_costprice;
			$res[$key]["goods_name"] = $goods_name?$goods_name:$res["goods_name"];
			$allcosprice=$allcosprice+$g_costprice * $goods["goods_number"];
			//获取订单的信息
			
		}


		$order = $this->fun->getdatabasesdetail("db_order_list"," AND order_id='".$id."'","shipping_fee,pay_fee,pack_fee,platform_fee,goods_amount,shipping_expectfee,shipping_realfee");
		$order["allmoney"] = $order["goods_amount"] ;
		if($order["shipping_realfee"]>0)
				$shippingfee = $order["shipping_realfee"];
			else
				$shippingfee = $order["shipping_expectfee"];
		
		if(!$shippingfee) $shippingfee = 0;
		$order["cosprice"] = $allcosprice;
		$order["shippingfee"] = $shippingfee;
		
		$order["subtotal"] = $order["allmoney"] +$order["shipping_fee"]- $order["platform_fee"] - $order["pay_fee"]-$order["pack_fee"] - $allcosprice-$shippingfee;
		$order["subtotal"] = round($order["subtotal"],2);
	
		return array("res"=>$res,"order"=>$order);
	}
	/*****************
	** 查询订单所有快递方式
	** $id int
	*************/
	function getorderexpress($id="")
	{
		$this->db->order_by("id","DESC");
		$post=array("status"=>0);
		if($id)$post=array("id"=>$id);
		return $this->db->get_where("db_order_express",$post)->result_array();
	}
	/*****************
	 ** 查询订单所有仓库
	 ** $id int
	 *************/
	function getWarehouses($id="")
	{
		//$this->db->order_by("id","DESC");
		$post=array("isdel"=>0);
		if($id)$post=array("id"=>$id);
		return $this->db->get_where("db_storage",$post)->result_array();
	}
	//查询指定店铺
	function getWhereShops()
	{
		$sql = "SELECT id,name FROM d_shop WHERE platfromname = 'Tmall' or platfromname = '淘宝' or (platfromname='Amazon' AND name in ('telacos','veribuy','Getime','Pattistore','Mesodyn')) or (name in ('jp-yahoo')) ";
		//$sql = "SELECT id,name FROM d_shop WHERE platfromname = 'Tmall' or platfromname = '淘宝' ";
		$rs  = $this->db->query($sql)->result_array();
		return $rs;
	}
	/****************************
	*** 显示历史订单记录
	*******************************/
	function historyorder($orderID)
	{
		$rsdb = $this->fun->getdatabasesdetail("db_order_list"," AND order_id ='".$orderID."'");
		$where = " 1 ";
		if($rsdb["tel"])
		{
			$where.= " AND tel='".$rsdb["tel"]."'";
		}
		if($rsdb["mobile"] && $rsdb["tel"]=='')
		{
			$where.= " AND mobile='".$rsdb["mobile"]."'";
		}
			$where.= " AND consignee='".addslashes($rsdb["consignee"])."'";
			$where.= " AND customerid='".addslashes($rsdb["customerid"])."'";
			
			$address = addslashes($rsdb["address"].$rsdb["address2"]);
			$where.= " AND address='".$address."'";
		
		if($where)
		$historyorder = $this->db->order_by("order_id", 'DESC')->limit($this->config->item('confighistoryordernum'))->get_where('db_order_list', "  $where AND order_id !='".$orderID."' AND order_status !=7 AND order_status !=6 ")->result_array();
		return $historyorder;
	}
	/****************************
	*** 获取所有店铺ID
	*******************************/
	function getshopIDlist($platfrom)
	{
		$rsdb = $this->fun->getdatabasesdetail("d_shop"," AND platfrom ='".$platfrom."' AND del_flag = 0"," GROUP_CONCAT(id) as shopid");
		if($rsdb)
		{
			return $rsdb["shopid"];
		}
	}

	/*******************
	** 保存新的订单信息
	**
	******************/
	function insertorderData()
	{
			$this->load->library('Amazondata');
			$postdata="";
			$postdata["order_sn"] = $this->amazondata->getNo();;
			$postdata["dates"] = date("Y-m-d");
			$postdata["order_status"] = 1;
			$postdata["order_source"] =$this->input->post('st');
			$postdata["customerid"] =addslashes(trim($this->input->post('customerid')));
			$postdata["tradeid"] =$this->input->post('tradeid');
			$postdata["consignee"] =addslashes(trim($this->input->post('consignee')));
			$postdata["country"] = $this->input->post('country');
			$rscountry = $this->db->get_where("d_country","countrynamecn='".$this->input->post('country')."'")->result_array();
			if($rscountry[0]["id"]){
				$postdata["country_cn"] = $rscountry[0]["countrynameen"];
				$postdata["country_code"] = $rscountry[0]["countryid"];
			}
			$postdata["province"] = trim($this->input->post('province'));
			$postdata["city"] = trim($this->input->post('city'));
			$postdata["address"] = addslashes(trim($this->input->post('address')));
			$postdata["address2"] = "";
			$postdata["zipcode"] = trim($this->input->post('zipcode'));
			$postdata["tel"] = trim($this->input->post('tel'))?trim($this->input->post('tel')):0;
			$postdata["mobile"] = 0;
			$postdata["email"] =trim($this->input->post('email'));
			$postdata["shopid"] = intval($this->input->post('shopID'));
			$rshop = $this->db->get_where("d_shop","id=".intval($this->input->post('shopID')))->result_array();
			$postdata["shopname"] = $rshop[0]["name"];
			$postdata["shopoper"] = $rshop[0]["updateoper"];
			
			
			
			if($rshop[0]["shop_platform_fee"]>0)
			{
				$fee  =$rshop[0]["shop_platform_fee"];
				
			
			}else{
				if($rshop['platfromname']=='aliexpress')
				{
					$fee = 0.1;
				}elseif($rshop['platfromname']=='Magento')
				{
					$fee = 0.1;
				}elseif($rshop['platfromname']=='淘宝')
				{
					$fee = 0;
				}elseif($rshop['platfromname']=='Tmall')
				{
					$fee = 0.06;
				}elseif($rshop['platfromname']=='Shopee')
				{
					$fee = 0.03;
				}else{

					$fee = 0.15;
				}

			}
			
			
			$postdata["moneytype"] = strtoupper(trim($this->input->post('moneytype')));
			if($postdata["moneytype"])
			{
				$rsmoney = $this->db->get_where("d_moneyrate","name='".strtoupper($postdata["moneytype"])."'")->result_array();
			}

			$postdata['platformID']  = $rshop[0]['platfrom'];//平台
			

			$goods_originask = trim($this->input->post('goods_originask'));
			if($goods_originask)
			{
				$postdata["goods_originask"] = $goods_originask;

				
				if($rsmoney)
				{
					$postdata["goods_amount"] = $goods_originask * $rsmoney[0]["rate"];
				}else{
					$postdata["goods_amount"] =0;
				}
			}else{
				$postdata["goods_originask"]  =0;
			}
			
			$postdata['moneyrate']  = $rsmoney[0]["rate"];//汇率
			$shipping_originask = trim($this->input->post('shipping_originask'));
			if($shipping_originask)
			{
				$postdata["shipping_originask"] = $shipping_originask;
				if($rsmoney)
				{
					$postdata["shipping_fee"] =  $shipping_originask * $rsmoney[0]["rate"];
				}else{
					$postdata["shipping_fee"] =0;
				}
			}else{
				$postdata["shipping_originask"]  =0;
			}

			$postdata["add_time"] = time();
			$postdata["ordertime"] = date("Y-m-d H:i:s");
			$postdata["saleschannel"] = 'system';
			if($rshop[0]['platfromname']=='ebay')
			{
				$postdata["pay_fee"] = $goods_originask*$rsmoney[0]["rate"]*0.04;
			}else{

				if($rshop[0]["shop_pay_fee"]>0)
				{
					$fee_pay_fee  =$rshop[0]["shop_pay_fee"];
				}else{
					$fee_pay_fee = 0.015;
				}
				$postdata["pay_fee"] = $goods_originask*$rsmoney[0]["rate"]*$fee_pay_fee;
			}
			
			$postdata["platform_fee"] = $goods_originask*$rsmoney[0]["rate"]*$fee;
			$postdata["platform_message"] =trim($this->input->post('platform_message'));
			$postdata["remark"] =trim($this->input->post('remark'));
				//存SKU

			
			$rsdb = $this->db->get_where("db_factory","code >0")->result_array();
			foreach($rsdb as $key =>$rs)
			{
				$factorycode[] = $rs["code"];	//工厂编号
			}
			$this->db->trans_begin();	//事务开始
			
				$this->db->insert("db_order_list",$postdata);
				$orderID = $this->db->insert_id();
				
				$goods_id = $this->input->post('goods_id');
				$goods_sku = $this->input->post('goods_sku');
				$nums = $this->input->post('nums');
				$price = $this->input->post('price');
				if(goods_id){
				
			
				foreach($goods_sku as $key=>$res)
				{
					$rgoods = $this->db->get_where("db_goods","goods_sku='".$res."'")->result_array();
					if($rgoods[0]["goods_id"])
					{
						$goods_id = $rgoods[0]["goods_id"];
						$sweight = $nums[$key] * $rgoods[0]["g_weight"];
						$weight = $weight+$sweight;
						/*****************成本价计算方式********
						**  11、12开头定制的衣服按成本价计算
						**  批量的sku 按关联价计算
						**  外采购的衣服按成本价计算
						*********************************/
						$costprice = 0;
						if(is_numeric($res) && preg_match('|^\d{8}$|',$res))	//数字并且8位SKU并且11 12开头
						{
							$goodscode  = substr($res,0,2);//取开头2位数
							if(in_array($goodscode,$factorycode))	//是否存在在工厂code
							{
								$costprice = $rgoods[0]["g_costprice"];	//定制衣服按成本价计算
							}
						}else{
							//如果当前SKU不是8位，查询父SKU是不是8位并且11，12开头
							if(is_numeric($rgoods[0]["goods_parent_sku"]) && preg_match('|^\d{8}$|',$rgoods[0]["goods_parent_sku"]))	//数字并且8位SKU并且11 12开头
							{
								$goodscodes  = substr($rgoods[0]["goods_parent_sku"],0,2);//取开头2位数
								if(in_array($goodscodes,$factorycode))	//是否存在在工厂code
								{
									$costprice = $rgoods[0]["bulkprice"];	//批量按关联价计算
								}
							}else{
								$costprice = $rgoods[0]["g_costprice"];
							}
							
						}
						
					}else{
						$goods_id = 0 ;
						$costprice = 0;
					}
					if($this->input->post('moneytype'))
					{
						$rsmoney = $this->db->get_where("d_moneyrate","name='".strtoupper($this->input->post('moneytype'))."'")->result_array();
						
					}

					$pricest = $price[$key]*$rsmoney[0]["rate"];
					$postsell = "";
					$postsell["order_id"] = $orderID;
					$postsell["goods_id"] = $goods_id;
					$postsell["goods_name"] = addslashes($rgoods[0]["goods_name"]);
					$postsell["goods_sn"] = $rgoods[0]["goods_sku"];
					$postsell["costprice"] = $costprice;
					$postsell["goods_number"] = $nums[$key];
					$postsell["goods_price"] = $pricest;
					$postsell["goods_weight"] = $rgoods[0]["g_weight"]?$rgoods[0]["g_weight"]:0;
					$postsell["goods_amount"] = $nums[$key] * $pricest;
					if($rsmoney[0]["rate"]){
						$postsell["originsellprice"] =$price[$key];
					}else{
						$postsell["originsellprice"] =0;
					}

				
					$postsell["originsku"] = $rgoods[0]["goods_sku"];
					$this->db->insert("db_order_sell",$postsell);

					
					}
					if($weight)
					{
						$this->db->update("db_order_list",array("orderweight"=>$weight),"order_id=".$orderID);
					}

				}

				//更新日志
				$imgdata["goods_id"] = $orderID;	//订单ID
				$imgdata["updatetime"] = date("Y-m-d H:i:s");
				$imgdata["createUid"] = 0;
				$imgdata["types"] = 3;
				$imgdata["content"] ="新建订单->".$this->input->post('st');
				$imgdata["createUser"] =$_COOKIE["username"];
				$this->db->query($this->db->insert_string('db_goods_log', $imgdata));
				
				

				if ($this->db->trans_status() === FALSE)
				{
					$this->db->trans_rollback();
				}
				else
				{
					$this->db->trans_commit();
				}
		
				return $orderID;
	}
	/****************************
	*** 保存订单修改
	*******************************/
	function saveorderData()
	{
		$postdata=$rval="";
		$orderID = intval($this->input->post('orderId'));
		$rsdb = $this->fun->getdatabasesdetail("db_order_list"," AND order_id='".$orderID."'");
		$postdata["consignee"]	= trim($this->input->post('consignee'));
		$postdata["address"]	= trim($this->input->post('address'));
		$postdata["address2"]	= trim($this->input->post('address2'));
		$postdata["city"]		= trim($this->input->post('city'));
		$postdata["province"]   = trim($this->input->post('province'));
		$postdata["country"]	= trim($this->input->post('country'));
		if($postdata["country"] != $rsdb["country"])
		{
			$rval.= "修改国家：原".trim($rsdb["country"])." 更新为：".trim($postdata["country"])."<br>";
			$country = $this->fun->getdatabasesdetail("d_country"," AND countrynamecn = '".strtoupper($postdata["country"])."'");
			if($country)
			{
				$postdata["country_code"]	= trim($country["countryid"]);
				$postdata["country_cn"]	= trim($country["countrynameen"]);
			}
		}
        $postdata["payid"]    = trim($this->input->post('payid'));
		if($postdata['moneytypes'])
		{
			$postdata["moneytypes"]    = trim($this->input->post('moneytypes'));
			$rval.= "修改货币：原".trim($rsdb["moneytypes"])." 更新为：".trim($postdata["moneytypes"])."<br>";
		}

        $postdata["payaccount"]    = trim($this->input->post('payaccount'));
		$postdata["zipcode"]    = trim($this->input->post('zipcode'));
		$postdata["tel"]		= trim($this->input->post('tel'));
		$postdata["mobile"]		= trim($this->input->post('mobile'));
		$postdata["email"]		= trim($this->input->post('email'));
		$postdata["shipping_id"]= trim($this->input->post('shipping'));
		if($postdata["shipping_id"])
		{
			$shipping = $this->fun->getdatabasesdetail("db_order_express"," AND id = '".$postdata["shipping_id"]."'");
			if($shipping)$postdata["shipping_name"]= trim($shipping['name']);
			if(!$shipping['oversea_express'])
			{
				$postdata["shipping_status"]=5;
			}
			
			if($rsdb["shipping_id"]==0)
			{
				$rsdb["shipping_name"] = "NULL";
			}
			if($postdata["shipping_id"] != $rsdb["shipping_id"]) $rval.= "修改物流方式：原".trim($rsdb["shipping_name"])." 更新为：".trim($postdata["shipping_name"])."<br>";
		}
		$postdata["actionorderweight"]= trim($this->input->post('actionorderweight'));
		$postdata["shipping_number"]		= trim($this->input->post('shipping_number'));
		$postdata["shipping_realfee"]		= trim($this->input->post('shipping_realfee'));
		$postdata["orderweight"]		= trim($this->input->post('orderweight'));
		
			if($postdata["orderweight"] >=2000)
			{
				$postdata["is_overweight"] = 1;
			}else{
				$postdata["is_overweight"] = 2;
			}
		
		$postdata["remark"]		= trim($this->input->post('remark'));
		$postdata["shipping_expectfee"]		= trim($this->input->post('shipping_expectfee'));
		if($postdata["shipping_number"] != $rsdb["shipping_number"])
		{
			$postdata["shipping_time"]		=time();
		}
		
		if(trim($this->input->post('customerid')) != $rsdb["customerid"])
		{
			$postdata["customerid"]=trim($this->input->post('customerid'));
		}
	
		if($postdata["consignee"] != $rsdb["consignee"]) $rval.= "修改收件人：原".trim($rsdb["consignee"])." 更新为：".trim($postdata["consignee"])."<br>";
		if($postdata["address"] != $rsdb["address"]) $rval.= "修改地址：原".trim($rsdb["address"])." 更新为：".trim($postdata["address"])."<br>";
		if($postdata["address2"] != $rsdb["address2"]) $rval.= "修改地址：原".trim($rsdb["address2"])." 更新为：".trim($postdata["address2"])."<br>";
		if($postdata["city"] != $rsdb["city"]) $rval.= "修改CITY：原".trim($rsdb["city"])." 更新为：".trim($postdata["city"])."<br>";
		if($postdata["province"] != $rsdb["province"]) $rval.= "修改province：原".trim($rsdb["province"])." 更新为：".trim($postdata["province"])."<br>";
		if($postdata["zipcode"] != $rsdb["zipcode"]) $rval.= "修改邮编：原".trim($rsdb["zipcode"])." 更新为：".trim($postdata["zipcode"])."<br>";
		if($postdata["tel"] != $rsdb["tel"]) $rval.= "修改电话：原".trim($rsdb["tel"])." 更新为：".trim($postdata["tel"])."<br>";
		if($postdata["mobile"] != $rsdb["mobile"]) $rval.= "修改电话2：原".trim($rsdb["mobile"])." 更新为：".trim($postdata["mobile"])."<br>";
		if($postdata["email"] != $rsdb["email"]) $rval.= "修改邮箱：原".trim($rsdb["email"])." 更新为：".trim($postdata["email"])."<br>";
		if($postdata["actionorderweight"] != $rsdb["actionorderweight"]) $rval.= "修改称重重量：原".trim($rsdb["actionorderweight"])." 更新为：".trim($postdata["actionorderweight"])."<br>";
		
		if($rsdb["shipping_number"]){
			if($postdata["shipping_number"] != $rsdb["shipping_number"]) $rval.= "修改运单号：原".trim($rsdb["shipping_number"])." 更新为：".trim($postdata["shipping_number"])."<br>";
		}
		if($rsdb["shipping_realfee"] !='0.00'){
			if($postdata["shipping_realfee"] != $rsdb["shipping_realfee"]) $rval.= "修改运费：原".trim($rsdb["shipping_realfee"])." 更新为：".trim($postdata["shipping_realfee"])."<br>";
		}
		if($postdata["orderweight"] != $rsdb["orderweight"]) $rval.= "修改重量：原".trim($rsdb["orderweight"])." 更新为：".trim($postdata["orderweight"])."<br>";
		if(trim($postdata["remark"]) != trim($rsdb["remark"])) $rval.= "修改备注：原".trim($rsdb["remark"])." 更新为：".trim($postdata["remark"])."<br>";
		if($postdata["shipping_expectfee"] != $rsdb["shipping_expectfee"]) $rval.= "修改预估运费：原".trim($rsdb["shipping_expectfee"])." 更新为：".trim($postdata["shipping_expectfee"])."<br>";

		if($postdata)
		{
			if($this->db->update("db_order_list",$postdata,"order_id=".$orderID))
			{
				if($rval){
					$this->fun->goods_update_log($orderID,$rval,3);	//日志
				}
				
			}

			return $orderID;
		}
		
	}


	function saveBulkchanges()
	{
		$orderlist = $this->input->post('orderlist');
		$expresstype  = $this->input->post('expresstype');
		if($orderlist)
		{
			$orderlist = explode("\n",$orderlist);
			foreach($orderlist as $key=>$res)
			{
				$res = trim($res);
				if($res){
					$rsdb = $this->fun->getdatabasesdetail("db_order_list"," AND order_sn ='".$res."'");
					
					$old = $rsdb["shipping_name"]?$rsdb["shipping_name"]:"未填写";

					if(!$expresstype)
					{
						$post="";
						$post["shipping_id"] = 0;
						$post["shipping_name"]="";
						$this->db->update("db_order_list",$post,"order_sn='".$res."'");
						$rval= "批改物流方式：原->".$old."  更新为->取消现有的配送方式<br>";
						$this->fun->goods_update_log($rsdb["order_id"],$rval,3);	//日志
					}else{
						$post="";
						$post["shipping_id"] = $expresstype;
						$expresstypelist = $this->fun->getdatabasesdetail("db_order_express"," AND id='".$expresstype."'");
						$post["shipping_name"]=$expresstypelist["name"];
						$rval= "批改物流方式：原->".$old."  更新为->".$expresstypelist["name"]."<br>";
						$this->fun->goods_update_log($rsdb["order_id"],$rval,3);	//日志
						$this->db->update("db_order_list",$post,"order_sn='".$res."'");
					}
				}
			}
		}
		return true;
	}
	//交运对账信息
	public function getDeliverBill($objExcel,$deliverType){
		//E邮宝或cnpost 或燕文
		if($deliverType==8||$deliverType==11||$deliverType==7){
			$sheet = $objExcel->getSheet(0);
		}
		//云途
		if($deliverType==6){
			$sheet = $objExcel->getSheet(4);
		}
		$rows = $sheet->getHighestRow(); //总行数
		$cols = $sheet->getHighestColumn(); //总列数 英文大写字母
		$arrCellName = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
			'Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU',
			'AV','AW','AX','AY','AZ');
		$cols_length = array_search($cols, $arrCellName); //获取数组下标最大数
		$arr_deliver = array();
		$str_conn = "";
		/**
		 * 燕文 begin
		 */
		if($deliverType==7){
			//行
			for($row=1;$row<=$rows;$row++){
				//列
				for($column=0;$column<= $cols_length;$column++){
					$cellValue = $arrCellName[$column].$row; //A2
					$col_val = $sheet->getCell($cellValue)->getValue();
					$col_val_len = strlen($col_val);
					//运单号
					if($column==1){
						//燕文
						if($col_val_len == 11 || $col_val_len==13){
							$arr_deliver[$row]['deliverNumber'] = $col_val;
							$str_conn.="'".$col_val."'".",";
						}else{
							break;
						}
					}
					if($column==6){
						$arr_deliver[$row]['deliverWeight'] = $col_val;
					}
					//资费
					if($column==13){
						$arr_deliver[$row]['deliverFee'] = $col_val;
					}

				}
			}
		}
	//燕文 end
		/**
		 * 云途 begin
		 */
		if($deliverType==6){
			//行
			for($row=1;$row<=$rows;$row++){
				//列
				for($column=0;$column<= $cols_length;$column++){
					$cellValue = $arrCellName[$column].$row; //A2
					$col_val = $sheet->getCell($cellValue)->getValue();
					$col_val_len = strlen($col_val);
					//运单号
					if($column==0){
						//燕文
						if($col_val_len == 18){
							$arr_deliver[$row]['deliverNumber'] = $col_val;
							$str_conn.="'".$col_val."'".",";
						}else{
							break;
						}
					}
					if($column==11){
						$arr_deliver[$row]['deliverWeight'] = $col_val;
					}
					//资费
					if($column==19){
						$arr_deliver[$row]['deliverFee'] = $col_val;
					}

				}
			}
		}
	//云途 end
		/**
		 * E邮宝 cnpost begin
		 */
		if($deliverType==8||$deliverType==11){
			//行
			for($row=1;$row<=$rows;$row++){
				//列
				for($column=0;$column<= $cols_length;$column++){
					$cellValue = $arrCellName[$column].$row; //A2
					$col_val = $sheet->getCell($cellValue)->getValue();
					$col_val_len = strlen($col_val);
					//运单号
					if($column==0){
						//燕文
						if($col_val_len == 13){
							$arr_deliver[$row]['deliverNumber'] = $col_val;
							$str_conn.="'".$col_val."'".",";
						}else{
							break;
						}
					}
					if($column==3){
						$arr_deliver[$row]['deliverWeight'] = $col_val;
					}
					//资费
					if($column==7){
						$arr_deliver[$row]['deliverFee'] = $col_val;
					}

				}
			}
		}
		//E邮宝 cnpost end

		$arr_tmp = array();
		$deliver_sort = array();
		$total_money = 0;
		$fuman_money = 0;
		$chajia_money = 0;
		$str_conn = trim($str_conn,",");
		$sql = "SELECT shipping_number,orderweight,shipping_fee,order_sn,actionorderweight,shipping_expectfee FROM db_order_list WHERE shipping_number in ($str_conn) ";
		$rs  = $this->db->query($sql)->result_array();
		//print_r($sql);exit;
		foreach($rs as $key=>$value){
			$arr_tmp[] = $value['shipping_number'];
		}
		foreach($arr_deliver as $kk=>$vv){
			if(in_array($vv['deliverNumber'],$arr_tmp)){
				//获取键值
				$key = array_search($vv['deliverNumber'],$arr_tmp);
				$weight = $rs[$key]['actionorderweight'];
				$fee = $rs[$key]['shipping_expectfee'];
				$order_sn = $rs[$key]['order_sn'];

				$arr_deliver[$kk]['id']=$kk;
				$arr_deliver[$kk]['deliverNumber']=$vv['deliverNumber'];
				$arr_deliver[$kk]['deliverFee']=$vv['deliverFee'];
				$arr_deliver[$kk]['deliverWeight']=$vv['deliverWeight'];
				//复漫
				$arr_deliver[$kk]['orderId']= $order_sn;
				$arr_deliver[$kk]['fee']= $fee;
				$arr_deliver[$kk]['weight']= $weight;
				$total_money = $total_money+$vv['deliverFee'];
				$fuman_money = $fuman_money+$fee;
				$chajia_money= $chajia_money+$vv['deliverFee'];
				//sort
				$deliver_sort[$kk] = $order_sn;

			}else{
				$arr_deliver[$kk]['id']=$kk;
				$arr_deliver[$kk]['deliverNumber']=$vv['deliverNumber'];
				$arr_deliver[$kk]['deliverFee']=$vv['deliverFee'];
				$arr_deliver[$kk]['deliverWeight']=$vv['deliverWeight'];
				$arr_deliver[$kk]['orderId']= "";
				$arr_deliver[$kk]['fee']= 0;
				$arr_deliver[$kk]['weight']= 0;
				$total_money = $total_money+$vv['deliverFee'];
				$fuman_money = $fuman_money+0;
				$chajia_money= $chajia_money+0;

				$deliver_sort[$kk] = "";
			}
		}
		@array_multisort($deliver_sort,SORT_ASC,$arr_deliver); //排序

		//print_r($sql);exit;
		$arr_rs = array($arr_deliver,$total_money,$fuman_money,$chajia_money);
		return $arr_rs;
	}



}

/* End of file Orderlist_m.php */